package net.jueb.custom.protocol;


import java.io.ByteArrayOutputStream;
import net.jueb.custom.pojo.NMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class NMsgEncoder extends MessageToByteEncoder<NMsg>{

	@Override
	protected void encode(ChannelHandlerContext ctx, NMsg msg, ByteBuf out)throws Exception {
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		bos.write(NMsg.Integer2Bytes(msg.toByteArray().length));//写入整体长度 注意，高位在前
		bos.write(msg.toByteArray());//写入整体数据
		bos.flush();
		out.writeBytes(bos.toByteArray());
	}



}
